package com.main.login.interfaces.facade;

import com.main.common.base.resp.RespBody;
import com.main.common.enums.LimitType;
import com.main.common.interfaces.AccessLimit;
import com.main.common.interfaces.SessionLocale;
import com.main.common.utils.common.RedisUtils;
import com.main.login.application.service.AccountService;
import com.main.login.interfaces.dto.AccountDTO;
import com.main.login.interfaces.dto.AddAccountDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Login", description = "系统用户接口")
@RestController
@RequestMapping("")
public class AccountFacade {

    @Resource
    private AccountService accountService;
    @Autowired
    private RedisUtils redisUtils;

    @GetMapping("/add")
    public String  add(@NotBlank String Id) {
        return "accountService.add()";
    }

    @Operation(summary = "添加账号", description = "输入用户信息进行注册")
    @PostMapping("/addAccount")
    @AccessLimit(key = "addAccount", period = 60, count = 10, name = "addAccount", prefix = "APILimit" ,limitType = LimitType.IP)
    public RespBody<AddAccountDTO> addAccount(@Validated @RequestBody AddAccountDTO addAccountDTO) {
        redisUtils.set("aaa", addAccountDTO.toString());
//        int time = 2005;
//        try {
//            Thread.sleep(time);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return accountService.addAccount(addAccountDTO);
    }

//    @Value("${server.port}")
//    private Integer port;

    @GetMapping("/getAccountList")
    @AccessLimit(key = "getAccountList", period = 60, count = 1, name = "getAccountList", prefix = "APILimit" ,limitType = LimitType.IP)
    public RespBody<List<AccountDTO>> getAccountList(HttpSession httpSession) {
        return accountService.getAccountList();
    }
}
